# include <bits/stdc++.h>
using namespace std;

int month[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

vector <pair<int, int> > d;

int get_days(int m1, int d1, int m2, int d2) { // 保证m2d2在m1d1之后
    int days = 0;
    for(int i = m1; i < m2; i++) days += month[i];
    days += d2 - d1;
    return days;
}

int main() { 
    freopen("heaven.in", "r", stdin);
    freopen("heaven.out", "w", stdout);
    int n, m0 = 1, d0 = 0, max_days = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) { 
        int a, b;
        scanf("%d%d", &a, &b);
        d.push_back(make_pair(a, b));
    }
    d.push_back(make_pair(12, 32));
    sort(d.begin(), d.end());
    for(int i = 0; i < (int) d.size(); i++) { 
        max_days = max(max_days, get_days(m0, d0, d[i].first, d[i].second));
        m0 = d[i].first;
        d0 = d[i].second;
    }
    double ans = (double) (24 * 3600 * (max_days - 1)) / 366.0 + 0.5;
    printf("%d\n", (int) ans);
}